<template>
    <view>
        <uni-list v-if="user">
            <uni-list-item title="头像">
                <template v-slot:footer>
                    <image  class="slot-image logo" :src="user.headimg" mode="widthFix"></image>
                </template>
            </uni-list-item>
            <uni-list-item title="账号">
                <template v-slot:footer>
                    <text class="right-text">{{user.account}}</text>
                </template>
            </uni-list-item>
            <uni-list-item title="名称">
                <template v-slot:footer>
                    <text class="right-text">{{user.username}}</text>
                    
                </template>
            </uni-list-item>

            <uni-list-item title="角色">
                <template v-slot:footer>
                    <text class="right-text">{{user.role_name}}</text>
                </template>
            </uni-list-item>
            <uni-list-item title="登录密码" link @click="inputDialogToggle">
                <template v-slot:footer>
                    <text class="right-text">点击修改</text>
                </template>
            </uni-list-item>
        </uni-list>
        
        <button type="warn" class="login_out" @click="loginout()">退出登录</button>
        	<!-- 输入框示例 -->
        <uni-popup ref="inputDialog" type="dialog">
            <uni-popup-dialog ref="inputClose" mode="input" title="修改密码" value=""
                placeholder="请输入内容" @confirm="dialogInputConfirm"></uni-popup-dialog>
        </uni-popup>
        <view class="fix-arge" @click="toLink">
          <text>《隐私政策》</text>
        </view>
    </view>
</template>

<script>
    export default {
      name:"basic",  
      data() {
        return {
          constants: {},
          user:null
        };
      },
      onLoad(){
        this.getuser()  
      },
      methods: {
      toLink () {
        const url = 'http://nantongapi.iceand.cn/arg.html';
        // #ifdef APP
        plus.runtime.openURL(url)
        // #endif
        // #ifdef H5
        location.href = url
        // #endif
      },
          loginout(){
              this.$api.post(`user/loginout`).then((res)=>{
                  uni.removeStorageSync('nangtong_login_token')
                  this.$navto('/pages/login/index')
              })
              // uni.getStorageSync('nangtong_login_token');
          },
            dialogInputConfirm(val) {
                this.$api.post(`user/editpass`,{pass:val}).then((res)=>{
                    this.$success("修改成功")
                    this.$refs.inputDialog.close()
                })
            },
            inputDialogToggle() {
                this.$refs.inputDialog.open()
            },
          getuser(){
              this.$api.get(`user/main`).then((res)=>{
                  this.user = res.data
              })
          }
      },
    };    
</script>

<style lang="less">
    .logo{
        width: 80rpx;
        height: 80rpx;
        border-radius: 50%;
    }
    .right-text{
        font-size: 24rpx;
        color: #8f939c;
    }
    .login_out{
        width: 90%;
        margin: 0 auto;
        margin-top: 50rpx;
    }
    .fix-arge {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 30rpx;
      color: #007aff;
      opacity: 0.6;
      margin-top: 30rpx;
    }
</style>